package com.fa.oj.judge.strategy;

import com.fa.oj.judge.codesandbox.model.JudgeInfo;
import com.fa.oj.model.entity.QuestionSubmit;
import com.fa.oj.model.enums.QuestionSubmitLanguageEnum;
import org.springframework.stereotype.Service;

/**
 * ClassName: JudgeManager
 * Package: com.fa.oj.judge.strategy
 * Description: 判题管理，根据编程语言选择判题策略（简化调用）
 *
 * @Author:
 * @Create: 2024/4/23 - 22:04
 * @Version: v1.0
 */
@Service
public class JudgeManager {

    /**
     * 执行判题
     * @param judgeContext
     * @return
     */
    public JudgeInfo doJudge(JudgeContext judgeContext) {
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();
        JudgeStrategy judgeStrategy = new DefaultJudgeStrategy();
        if (language.equals(QuestionSubmitLanguageEnum.JAVA.getValue())) {
            judgeStrategy = new JavaLanguageJudgeStrategy();
        }
        return judgeStrategy.doJudge(judgeContext);
    }
}
